package com.feng.dt.service.impl;

import com.feng.common.exception.ErrorCode;
import com.feng.common.exception.ValidationException;
import com.feng.dt.model.entity.ScheduleJobLog;
import com.feng.dt.service.ScheduleJobLogService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * @author Lee
 */
@Service
public class ScheduleJobLogServiceImpl implements ScheduleJobLogService {

    private final static Logger LOGGER = LoggerFactory.getLogger(ScheduleJobLogServiceImpl.class);

    @PersistenceContext
    private EntityManager em;

    @Transactional
    @Override
    public void save(ScheduleJobLog scheduleJobLog) throws ValidationException {
        try {
            em.persist(scheduleJobLog);
        } catch (Exception e) {
            String msg = String.format("任务日志保存失败，Params：[%s]",scheduleJobLog);
            LOGGER.error(msg);
            throw new ValidationException(ErrorCode.SystemError,msg);
        }
    }
}
